<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page session="true" %>
<!DOCTYPE html>
<html>
<head>
    <title>Login</title>
</head>
<body>
<h1>登录页</h1>
<form action="index.jsp" method="post">
    <label for="username">用户名:</label>
    <input type="text" id="username" name="username"><br>
    <label for="password">密码:</label>
    <input type="password" id="password" name="password"><br>
    <input type="submit" value="登录">
    | <a href="register.jsp">注册</a>
</form>

<jsp:useBean id="userDAO" class="org.example.week10.UserDAO" scope="page"/>

<c:if test="${not empty param.username and not empty param.password}">
    <c:choose>
        <c:when test="${param.username eq '永远的神' and param.password eq '123'}">
            <c:set var="user" value="${param.username}" scope="session"/>
            <c:set var="admin" value="1" scope="session"/>
            <c:redirect url="admin-service.jsp"/>
        </c:when>

        <c:otherwise>
            <c:set var="user" value="${userDAO.getUserByName(param.username)}"/>
            <c:choose>
                <c:when test="${not empty user and user.pwd eq param.password}">
                    <c:set var="user" value="${param.username}" scope="session"/>
                    <c:redirect url="service.jsp"/>
                </c:when>
                <c:otherwise>
                    <p style='color:red;'>用户名还未审核通过，请联系管理员【永远的神】</p>
                </c:otherwise>
            </c:choose>
        </c:otherwise>
    </c:choose>
</c:if>

</body>
</html>